#ifndef POBJECT_H
#define POBJECT_H

#include <QObject>

#include <physics/pvector.h>

class PWorld;
class QDomElement;
class QDomNode;
class QDomDocument;

/**
  * Object in the world.
  */
class PObject : public QObject
{
    Q_OBJECT
public:
    /**
      * Creates object in world "world" with name "name".
      */
    explicit PObject(PWorld *world, QString name = "");

    /**
      * Deletes object.
      */
    virtual ~PObject();

    /**
      * Moves object during time "t".
      */
    void move(double t);

    /**
      * Counts distance from object to object "o".
      */
    double distanceTo(PObject *o);

    /**
      * Counts square of distance from object to object "o".
      */
    double distanceSqrTo(PObject *o);

    /**
      * Hits object "obj".
      */
    void hit(PObject *obj);

    /**
      * Returns position of object.
      */
    PVector getPos() const;

    /**
      * Returns X coordinate of object.
      */
    double getX() const;

    /**
      * Retruns Y coordinate of object.
      */
    double getY() const;

    /**
      * Returns velocity of object.
      */
    PVector getV() const;

    /**
      * Returns mass of object.
      */
    double getM() const;

    /**
      * Returns radius of object;
      */
    double getR() const;

    /**
      * Returns world of this object.
      */
    PWorld *getWorld() const;

    /**
      * Returns current accelerate of this object.
      */
    PVector getA() const;

    /**
      * Returns life of this object.
      */
    int getLife() const;

    /**
      * Returns damage.
      */
    int getDamage() const;

    /**
      * Returns brightness.
      */
    int getBrightness() const;

    /**
      * Returns name.
      */
    QString getName() const;

    /**
      * Returns type.
      */
    QString getType() const;

    /**
      * Sets position.
      */
    void setPos(PVector pos);
    void setPos(double x, double y);

    /**
      * Sets velocity.
      */
    void setV(PVector v);
    void setV(double x, double y);

    /**
      * Sets mass.
      */
    void setM(double m);

    /**
      * Sets radius.
      */
    void setR(double r);

    /**
      * Sets accelerate.
      */
    void setA(PVector a);

    /**
      * Sets life.
      */
    void setLife(int life);

    /**
      * Decreases life with "life".
      */
    void decLife(int life);

    /**
      * Sets damage.
      */
    void setDamage(int damage);

    /**
      * Sets brightness.
      */
    void setBrightness(int brightness);

    /**
      * Sets object to be removed.
      */
    void willBeRemoved();

    /**
      * Serializes object.
      */
    virtual void serialize(QDomDocument *doc, QDomElement *e) const;

    /**
      * Deserializes object.
      */
    static PObject *deserialize(QDomNode *e, PWorld *parent);

signals:

public slots:

private:
    PVector myPos;
    PVector myV;
    PVector myA;
    double myM;
    double myR;
    PWorld *myWorld;
    QString myName;
    int myLife;
    int myDamage;
    int myBrightness;
};

#endif // POBJECT_H
